package hehe.aop;

import hehe.aop.base.Aspect;
import hehe.aop.base.Behavior;

import java.util.Map;

/**
 * 切面类
 *<B>说明：</B>
 *<pre>
 * 略
 *</pre>
 *<B>示例：</B>
 *<pre>
 *  略
 *</pre>
 *<B>日志：</B>
 *<pre>
 *  略
 *</pre>
 *<B>注意事项：</B>
 *<pre>
 *  略
 *</pre>
 */
public class Aop
{
    public final static String BEFORE_EVENT = "Before";
    public final static String AFTER_EVENT = "After";
    public final static String THROW_EVENT = "Throw";
    public final static String FINALLY_EVENT = "Finally";
    public final static String AROUND_EVENT = "Around";

    public static AopManager getAopManager()
    {
       return AopManager.getAopManager();
    }

    public static Aspect getAspect(String expression)
    {
        return getAopManager().getAspect(expression);
    }

    /**
     * 执行拦截器
     *<B>说明：</B>
     *<pre>
     *  略
     *</pre>
     */
    public static void triggerInterceptor(Aspect aspect, String advice, Object target)
    {
        getAopManager().triggerInterceptor(aspect,advice,target);
    }

    /**
     * 触发事件
     *<B>说明：</B>
     *<pre>
     *  略
     *</pre>
     */
    public static void triggerEvent(String eventName,Map<String,Object> attrs)
    {
        getAopManager().triggerEvent(eventName,attrs,null);
    }

    /**
     * 触发事件
     *<B>说明：</B>
     *<pre>
     *  略
     *</pre>
     */
    public static void triggerEvent(String eventName)
    {
        getAopManager().triggerEvent(eventName,null,null);
    }

    /**
     * 注册事件行为
     *<B>说明：</B>
     *<pre>
     *  略
     *</pre>
     */
    public static void registerEventBehavior(String eventName,Class<? extends Behavior> ... behaviors)
    {
        for (Class<? extends Behavior> behavior:behaviors) {
            getAopManager().addEventBehavior(eventName,behavior);
        }
    }

    /**
     * 创建代理对象
     *<B>说明：</B>
     *<pre>
     *  略
     *</pre>
     */
    public static <T> T getProxy(Object target)
    {
        return (T)getAopManager().getProxy(target);
    }
}
